﻿<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>MonArch Mobile 7.51</title>
    <link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css"
        rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=true&language=ko" />

    <script src="/js/jquery.js" type="text/javascript"></script>
    <script src="/js/jquery-1.6.1.min.js" type="text/javascript"></script>
    <script src="/smkim.js" type="text/javascript"></script>
    <script src="/jquery.mobile/jquery.mobile-1.0b1/jquery.mobile-1.0b1.min.js" type="text/javascript"></script>
	<script src="/experiments/themeswitcher/jquery.mobile.themeswitcher.js" type="text/javascript"></script>
	<script src="/docs/_assets/js/jqm-docs.js" type="text/javascript"></script>
    <script type="text/javascript" src="/js/jquery.kdb.soap.js"></script>

    <script type="text/javascript">
        var map;
        var geocoder;
        var infowindow;
        var arrMarker = Array();

        //현재위치 변수
        var initialLocation;
        var siberia = new google.maps.LatLng(60, 105);
        var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687); 
        var browserSupportFlag = new Boolean();


        function detectBrowser() {
            var useragent = navigator.userAgent;
            var mapdiv = document.getElementById("map_canvas");

            //if (useragent.indexOf('iPhone') != -1 || useragent.indexOf('Android') != -1) {
                mapdiv.style.width = '100%';
                mapdiv.style.height = '100%';
            //} else {
            //    mapdiv.style.width = '600px';
            //    mapdiv.style.height = '700px';
            //}
        }

        function initialize() {

           
            var myLatlng = new google.maps.LatLng(37.56641923090, 126.9778741551);
            var myOptions = {
                zoom: 12,
                center: myLatlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            }

            map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
           

            var q1 = getUrlVars()["q1"];
            var q2 = getUrlVars()["q2"];

           
            if (q1 == undefined) {
          

                //내위치
                NavigatorGeolocation();
                
                //화면 사이즈
                detectBrowser();

            } else {

          
                var title = q2;
                if (title == undefined) title = "";

                //alert("2.q1:"+q1);
                showAddress(q1, title);
            }



        }
        function getUrlVars() {
            var vars = [], hash;
            var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
            for (var i = 0; i < hashes.length; i++) {
                hash = hashes[i].split('=');
                vars.push(hash[0]);
                vars[hash[0]] = hash[1];
            }
            return vars;
        }

        function handleNoGeolocation(errorFlag) {
            if (errorFlag == true) {
                alert("Geolocation service failed.");
                initialLocation = newyork;
            } else {
                alert("Your browser doesn't support geolocation. We've placed you in Siberia.");
                initialLocation = siberia;
            }
            map.setCenter(initialLocation);
        }
        function MapInit() {
            //지도 초기화
            for (var i = 0; i < arrMarker.length; i++) {
                arrMarker[i].setOptions({
                    map: null,
                    visible: false
                });
                arrMarker[i] = null;
            }

            arrMarker.length = 0;

        }

        function showAddress(address, title) {
            geocoder = new google.maps.Geocoder();

            address = decodeURI(address);
            title = decodeURI(title);

            this.geocoder.geocode({ 'address': address },
                           function (results, status) {
                               if (status == google.maps.GeocoderStatus.OK) {

                                   for (var i = 0; i < results.length; i++) {
                                       var vposition = results[0].geometry.location;
                                       //마커 생성.   
                                       //var vmarker = new google.maps.Marker({
                                       //    position: vposition,
                                       //    map: map
                                       //});

                                       var myOptions = {
                                           position: vposition,
                                           map: map
                                       };

                                       var marker = new google.maps.Marker(myOptions);
                                       arrMarker.push(marker);


                                       map.setCenter(vposition);
                                       marker.setPosition(vposition);
                                       marker.setTitle(address);
                                       //infowindow = new google.maps.InfoWindow();

                                       var infowindow = new google.maps.InfoWindow(
                                       { content: title,
                                           size: new google.maps.Size(50, 50)
                                       });
                                       infowindow.setContent("<b>" + title + "</b><p>" + address + "</p>");
                                       //infowindow.open(map, vmarker);

                                       google.maps.event.addListener(marker, 'click', function () {
                                           infowindow.open(map, marker);
                                       });


                                   }
                               }
                           });


            NavigatorGeolocation();


        }
        function NavigatorGeolocation() {

            //현재위치
            // Try W3C Geolocation (Preferred) 
            if (navigator.geolocation) {
                browserSupportFlag = true;
                navigator.geolocation.getCurrentPosition(function (position) {
                    initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                    map.setCenter(initialLocation);

                    var vmarker = new google.maps.Marker({
                        position: initialLocation,
                        map: map
                    });

                    var infowindow = new google.maps.InfoWindow(
                                       { content: "내위치",
                                           size: new google.maps.Size(50, 50)
                                       });
                   //infowindow.open(map, vmarker);

                   google.maps.event.addListener(vmarker, 'click', function () {
                       infowindow.open(map, vmarker);
                   });

                }, function () {
                    //handleNoGeolocation(browserSupportFlag);
                });
                // Try Google Gears Geolocation 
            } else if (google.gears) {
                browserSupportFlag = true;
                var geo = google.gears.factory.create('beta.geolocation');
                geo.getCurrentPosition(function (position) {
                    initialLocation = new google.maps.LatLng(position.latitude, position.longitude);
                    map.setCenter(initialLocation);

                    var vmarker = new google.maps.Marker({
                        position: initialLocation,
                        map: map
                    });

                    var infowindow = new google.maps.InfoWindow(
                          { content: "내위치",
                            size: new google.maps.Size(50, 50)
                          });
                    //infowindow.open(map, vmarker);


                    google.maps.event.addListener(vmarker, 'click', function () {
                        infowindow.open(map, vmarker);
                    });

                }, function () {
                    //handleNoGeoLocation(browserSupportFlag);
                });
                // Browser doesn't support Geolocation 
            } else {
                browserSupportFlag = false;
                handleNoGeolocation(browserSupportFlag);
            } 


        }

        
    
    </script>
</head>
<body onload="initialize()">
    <div id="map_canvas" ></div>
   
</body>
</html>
